delphifandomcom-20200223-history
Live Templates Technical Info
General Structure A Live Template looks like this: Description goes here Author OfTheTemplate default text here hint for the user The actual content goes here. Elements * codetemplate ** template *** description - the text displayed in the template viewer *** author - the author of the template *** point* - 0..n place holders for text **** text - the default text **** hint - a hint to be displayed to the user *** code - the actual template **** .... *** script - this can apparently be added anywhere template element The template element is the main element containing all the others. It has the following attributes: Values for invoke: * auto - invoked by pressing SPACE or TAB * manual - invoked by pressing TAB * none - invoked by using CTRL+J, CTRL+SPACE, or using the template viewer description element The description element contains some descriptive text and apparently has no attributes. author element The author element contains the name of the template's author (this is free text, so it probably can contain anything, maybe an email address too?) point element A point element describes a place holder for text. It has the following attributes: There are some predefined points: * $selected$ - a non editable point that contains the text that is currently selected in the code editor * $end$ - marks the cursor position after the template has been executed * $*$ - An indentation based upon the current source options indentation settings (Equivalent to a single CTRL + SHIFT + I indentation level with the default keybinding) script element There is also an "onexit" attribute described in CodeTemplateApi.pas, but it seems to never be used in the existing templates. The following function calls are available in script elements (from existing templates): * language="Delphi": ** InvokeClassCompletion ** InvokeCodeCompletion (see delphi\trycf.xml) ** PopulateCase(|expression|) (see delphi\case.xml) ** DeclareVariable(|variable|) (see delphi\trycf.xml) ** RemoveTemplate (see delphi\inlinevar.xml) ** ValidateForTemplate (see delphi\fors.xml) * language="C": ** invoke_code_completion (see c\whiles.xml) ** populate_case($expr$); (see c\switch.xml) * language="DelphiExample" (see link below) ** GetClipboardContents (see clippy.xml) ** VarDeclToAssignment (see var.xml) code element * language - one of (List can be extended, see links below) ** Delphi ** C ** CSharp ** VB ** Jsharp (why is that written with a lower case "s"? ** HTML ** XML ** IDE ** SQL ** IDL ** JavaScript ** CSS ** INI ** PHP context can have the following values ("|" marks the place it describes): * memberdecl - TFoo = class(TComponent) | end; * methoddecl - procedure | * decl - var | * typedecl - type | * methodbody - begin | end; * page - reserved for future use * file - reserved for future use * any - any context According to CodeTemplateApi.pas there are the following additional values, which are probably not supported: * None - ? * Comment - inside a comment ? * StringLiteral - inside a string literal ? The default delimiter is "$", but since that may conflict with valid Delphi code like in s := 'line'#$0a'feed'; it can be changed (most seem to use "|"). The delimiter is used in the code in front and after a placeholder point name. Links * Delphi Live Templates in the Delphi Wiki with quite a lot examples * Nick Hodges Live Template Video Tutorial (no longer available) *Creating a script template engine by Daniel "sakura" Wischnewski *Creating live templates in BDS 2006 by Deborah Pate (on archive.org) *Creating Live template basics by Adam Markowitz (on archive.org) *Live Template examples by Adam Markowitz (on archive.org) *sync edit params (on archive.org) (not quite Live Templates related, but very interesting anyway) *"Creating a Live Templates Scripting Engine" by Nick Hodges (on archive.org) *"Live Templates: basics through to script engines" video presentation by Lachlan Gemmell for the Australian Delphi User Group Category:Source Code Category:Delphi IDE